//
//  ZYAttendanceRecordCell.m
//  优学荟管理系统
//
//  Created by edz on 2017/12/5.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "ZYAttendanceRecordCell.h"
#import "ZYAttendanceRecordModel.h"
@implementation ZYAttendanceRecordCell




- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUpSuperView];
    }
    
    
    return self;
    
    
    
}

- (void)assignByZYAttendanceRecordModel:(ZYAttendanceRecordModel *)model{
    
    
    self.nameLabel.text = [NSString stringWithFormat:@"%@",model.teacherName];
    
    BOOL isUp = [NSString isBlankString:model.avatar];
    
    if (isUp) {
        self.photoImageView.image = [UIImage imageNamed:@"bg_head"];
    }else{
        
        [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"bg_head"]];
    }
    
//    self.countLabel.text = [NSString stringWithFormat:@"%@",model.leaveCount];
//    self.countTowLabel.text = [NSString stringWithFormat:@"%@",model.signCount];
    
    NSMutableAttributedString *hintString=[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@次\n请假",model.leaveCount]];
    //获取要调整颜色的文字位置,调整颜色
    
    NSString *leaveCount = [NSString stringWithFormat:@"%@",model.leaveCount];
    
    NSRange range1=[[hintString string]rangeOfString:leaveCount];
    [hintString addAttribute:NSForegroundColorAttributeName value:ColorRGB(245,92,128) range:range1];
     [hintString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0f] range:range1];
    NSRange rangeTow=[[hintString string]rangeOfString:@"次"];
    [hintString addAttribute:NSForegroundColorAttributeName value:ColorRGB(245,92,128)   range:rangeTow];
    [hintString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0f] range:rangeTow];

    self.countLabel.attributedText=hintString;
    
    
    
    
    NSMutableAttributedString *hintStringTow=[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@次\n签到",model.signCount]];
    //获取要调整颜色的文字位置,调整颜色
    
    NSString *leaveCountTow = [NSString stringWithFormat:@"%@",model.signCount];
    
    NSRange rangeThree=[[hintStringTow string]rangeOfString:leaveCountTow];
    
    [hintStringTow addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:rangeThree];
    [hintStringTow addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0f] range:rangeThree];
    NSRange rangeFour=[[hintStringTow string]rangeOfString:@"次"];
    [hintStringTow addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor]   range:rangeFour];
    [hintStringTow addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11.0f] range:rangeFour];
    
    self.countTowLabel.attributedText=hintStringTow;
    
    
    
    
    
    
    
    
    
    
    
    
}




- (void)setUpSuperView{
    
    
    self.photoImageView = [UIImageView new];
    self.photoImageView.image = [UIImage imageNamed:@"bg_head"];
    self.photoImageView.layer.cornerRadius = 25;
    [self.contentView addSubview:self.photoImageView];
    
    self.nameLabel = [UILabel new];
    self.nameLabel.text = @"张宇";
    self.nameLabel.textColor = ColorRGB(102, 102, 102);
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.nameLabel];
    
    self.backGroundImageView  = [UIImageView new];
    self.backGroundImageView.image = [UIImage imageNamed:@"bg_qiandao"];
    [self.contentView addSubview:self.backGroundImageView];
    
    self.countLabel = [UILabel new];
    self.countLabel.numberOfLines = 0;
    self.countLabel.text = @"3次\n请假";
    self.countLabel.font = [UIFont systemFontOfSize:14];
    self.countLabel.textColor = ColorRGB(51, 51, 51);
    [self.backGroundImageView addSubview:self.countLabel];
    
    
    self.countTowLabel = [UILabel new];
    self.countTowLabel.text = @"20次\n请假";
    self.countTowLabel.numberOfLines = 0;
    self.countTowLabel.textColor = ColorRGB(51, 51, 51);
    self.countTowLabel.font = [UIFont systemFontOfSize:14];
    [self.backGroundImageView addSubview:self.countTowLabel];
    
    
    
    
    [self.photoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.offset(20);
        make.width.height.offset(50);
    }];
    
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.photoImageView.mas_right).offset(15);
        make.centerY.equalTo(self.photoImageView);
    }];
    
    
    [self.backGroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.centerY.equalTo(self.photoImageView);
    }];
    
    
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.centerY.equalTo(self.backGroundImageView);
    }];
    
    
    [self.countTowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.backGroundImageView).offset(-15);
        make.centerY.equalTo(self.backGroundImageView);
    }];
    
    UILabel *grayLabel = [UILabel new];
    grayLabel.backgroundColor = ColorRGB(247, 245, 245);
    [self.contentView addSubview:grayLabel];
    
    [grayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.equalTo(self.photoImageView.mas_bottom).offset(20);
        make.width.offset(kScreenWidth);
        make.height.offset(15);
    }];

    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.offset(0);
        make.bottom.mas_equalTo(grayLabel).offset(0);
        
    }];
    
    
    
    
    
    
}




































@end
